﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;

namespace Wimm.Common.Converters
{
    public class DecimalConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
                         object parameter, string language)
        {
            Decimal input = (Decimal)value;

            return input.ToString("N2");
        }

        public object ConvertBack(object value, Type targetType,
                                  object parameter, string language)
        {
            decimal d;
            if (value is string)
            {
                if (decimal.TryParse((string)value, out d))
                {
                    return d;
                }
            }
            return 0.0;
        }
    }
}
